package com.xcm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xcm.dao.ProgramInfoMapper;
import com.xcm.model.TbProgramInfo;
import com.xcm.model.dto.ProgramInfoListDTO;
import com.xcm.service.ProgramInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 节目信息Service实现类
 */
@Service(value = "programInfoService")
public class ProgramInfoServiceImpl implements ProgramInfoService {
	@Autowired
	private ProgramInfoMapper programInfoMapper;

	/**
	 * 批量保存节目信息
	 * @param programInfoList   List<TbProgramInfo>类型对象
	 */
	@Override
	@Transactional(readOnly = false, rollbackFor = Exception.class)
	public void saveProgramTopBatch(List<TbProgramInfo> programInfoList) {
		programInfoMapper.saveProgramInfoBatch(programInfoList);
	}

	/**
	 * 获取节目信息列表（分页）
	 * @param version   版本
	 * @param deviceNum 机器码
	 * @param pageNum   当前页
	 * @param pageSize  每页显示条数
	 * @return  Page<ProgramInfoListDTO>
	 */
	@Override
	public Page<ProgramInfoListDTO> listProgramInfoByPage(String version, String deviceNum, Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		return programInfoMapper.listProgramInfoByPage(version, deviceNum);
	}

	/**
	 * 通过机器码获取节目信息
	 * @param machineNum    机器码
	 * @return  TbProgramInfo
	 */
	@Override
	public TbProgramInfo getProgramInfoByMachineNum(String machineNum) {
		return programInfoMapper.getProgramInfoByMachineNum(machineNum);
	}
}
